<template>
  <div class="page">
    <Navbarelder title="我的评价" />
    <van-tabs v-model="activeTab" color="#4B93FE" @change="onRefresh">
      <van-tab title="待评价" :name="0" />
      <van-tab title="已评价" :name="1" />
    </van-tabs>
    <div class="content">
      <van-pull-refresh v-model="refreshLoading" @refresh="onRefresh">
        <van-empty v-if="!tableData.length" description="暂无数据" />
        <div class="list">
          <div
            v-for="(item,index) in tableData"
            :key="index"
            class="list-item"
          >
            <div class="header f-r j-b a-c">
              <div class="title">{{ item.projectName }}</div>
              <el-button v-if="activeTab === 0" type="primary" size="medium" @click.stop="routerJump(item)" >去评价</el-button>
            </div>
            <div class="label">
              项目类型：{{ item.projectType }}
            </div>
            <div class="label">
              项目进度：{{ item.statusName }}
            </div>
            <div class="label">
              代办员：{{ item.agencyPeople }} {{ item.mobile }}
            </div>
            <div class="label">
              服务状态：<span style="color: #1BA94D">{{ item.statusName }}</span>|{{ item.tableName }}
            </div>
            <div v-if="activeTab === 1" class="label f-r a-c">
              <span>满意度：</span>
              <van-rate
                :value="parseFloat(item.satisfaction)"
                allow-half
                :size="24"
                color="#F47526"
                void-icon="star"
                void-color="#eee"
              />
            </div>
            <div v-if="activeTab === 1" class="label">
              评价内容：{{ item.comment }}
            </div>
          </div>
        </div>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
import refresh from '@/mixins/refresh'
import { http_evaluation } from '@/api'
import { progressStatus } from '@/eumn'
import { Toast } from 'vant'
export default {
  name: 'Project',
  mixins: [refresh],
  data() {
    return {
      filterIcon: require('@/assets/home/filter.png'),
      tableData: [
      ],
      activeTab: 0,
      typeName: {
        计划变更: '1',
        外线联报: '2',
        咨询: '0'
      }
    }
  },
  methods: {
    routerJump(item) {
      this.$router.push({
        path: '/my-evaluation-create-elder',
        query: {
          id: item.id,
          projectId: item.projectId,
          tableName: item.tableName,
          types: this.typeName[item.tableName],
          vconsole: true
        }
      })
    },
    onRefresh() {
      this.pageNo = 1
      this.getList()
    },
    getList() {
      if (this.pageNo > 1 && this.tableData.length >= this.totalSize) return Toast('没有更多了')
      http_evaluation.page({
        ...this.getQueryParams(),
        contentStatus: this.activeTab
      }).then(res => {
        if (this.pageNo === 1) {
          this.tableData = res.data.records.map(el => {
            return {
              ...el,
              statusName: progressStatus.getName(el.status)
            }
          })
        } else {
          this.tableData = [
            ...this.tableData,
            ...res.data.records.map(el => {
              return {
                ...el,
                statusName: progressStatus.getName(el.status)
              }
            })
          ]
        }
        this.totalSize = res.data.total
        this.refreshLoading = false
      })
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .van-tab{
  font-size: 18px;
}
.page {
    .search-header {
        background-color: #fff;
        padding: 10px 0;
        padding-right: 0.32rem;
        .filter-box {
            flex-shrink: 0;
            font-size: 12px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #333333;
        }
    }
    .list-item {
        width: 100%;
        background: #FFFFFF;
        border-radius: 10px;
        padding: 20px;
        margin-bottom: 20px;
        .el-button {
            background: #2F86FD;
            border-color: #2F86FD;
            border-radius: 13px;
        }
        .header {
            .title {
                // height: 17px;
                font-size: 22px;
                font-family: PingFang SC;
                font-weight: 500;
                color: #333333;
                margin-right: 10px;
            }
            margin-bottom: 12px;
        }
        .label {
            font-size: 19px;
            line-height: 18px;
            font-family: PingFang SC;
            color: #999999;
            margin-bottom: 14px;
            &:last-of-type {
                margin-bottom: 0;
            }
        }
        ::v-deep .el-step {
            .el-step__title {
                width: 60px;
                font-size: 14px;
                line-height: 18px;
                font-family: PingFang SC;
                font-weight: 500;
                color: #999999;
                margin-top: 5px;
            }
        }
    }
}
</style>
